package com.stn.zjx.givingtreasure.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.activity.address.EditAddressActivity;
import com.stn.zjx.givingtreasure.activity.userwallet.UserTransferRecordDetailActivity;
import com.stn.zjx.givingtreasure.bean.UserTransferRecord;
import com.stn.zjx.givingtreasure.domain.UserAddressDomain;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;
import com.vondear.rxtools.RxActivityTool;

import java.util.ArrayList;
import java.util.List;

public class UserTransferRecordItemListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

   public List<UserTransferRecord> dataBeanList=new ArrayList<>();
   private LayoutInflater inflater;
   public Context context;

   public UserTransferRecordItemListAdapter(Context context) {
       inflater = LayoutInflater.from(context);
      this.context=context;
   }

   @Override
   public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       RecyclerView.ViewHolder vh = new IndexHolder(inflater.inflate(R.layout.item_user_transfer_record, parent, false));
       return vh;
   }
   @SuppressLint("SetTextI18n")
   @Override
   public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
                   IndexHolder ih= (IndexHolder) viewHolder;
       UserTransferRecord   dataBean= dataBeanList.get(i);
        String  date=ToolsUtils.getDate(dataBean.getTransferCreatedate(),"yyyy-MM-dd");
       ih.date_time.setText(date);
      switch (dataBean.getTransferProfitType()){
          case 0:
            ih.money.setText("+"+dataBean.getTransferMoney());
              break;
          case 1:
              ih.money.setText("-"+dataBean.getTransferMoney());
              break;
      }
      switch (dataBean.getTransferRecordType()){
          case 0:
              ih.type.setText(context.getString(R.string.transfer));
              break;
          case 1:
              ih.type.setText(context.getString(R.string.withdraw));
              break;
          case 2:
              ih.type.setText(context.getString(R.string.recharge_to_balance));
              break;
      }
      ih.now_money.setText(context.getString(R.string.balance)+": "+String.valueOf(dataBean.getTransferNowMoney()));
      ih.rootView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
                  Bundle bundle=new Bundle();
                  bundle.putSerializable("data",dataBean);
                  RxActivityTool.skipActivity(context, UserTransferRecordDetailActivity.class,bundle);
          }
      });
   }

   @Override
   public int getItemCount() {
       return dataBeanList.size();
   }
   public void refreshList(List<UserTransferRecord> dataBeans) {
       dataBeanList.removeAll(dataBeanList);
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void appendList(List<UserTransferRecord> dataBeans) {
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void clearList() {
       dataBeanList.removeAll(this.dataBeanList);
       notifyDataSetChanged();
   }


   public  class IndexHolder extends RecyclerView.ViewHolder{

             public View rootView;
          public TextView type;
          public  TextView now_money;
          public TextView date_time;
          public  TextView money;

        IndexHolder(@NonNull View itemView) {
           super(itemView);
           rootView=itemView;
            type=itemView.findViewById(R.id.type);
            now_money=itemView.findViewById(R.id.now_money);
            date_time=itemView.findViewById(R.id.date_time);
            money=itemView.findViewById(R.id.money);
        }
   }

}